package savehalloween;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

public class Tower {
	/**
     * @var img the image resource for the sprite
     */
    private Image img;
    /** 
     * @var sprite the monsters sprite
     */
    private Sprite sprite;
    
    private int xPos = 1;
    private int yPos = 1;
    
    public Tower(String imageSource){
        try {
            img = Image.createImage(imageSource);
        } catch (Exception ioex) {
            ioex.printStackTrace();
        }

        sprite = new Sprite(img, img.getWidth(), img.getHeight());
        sprite.defineReferencePixel((int)img.getWidth()/2, (int) img.getHeight()/2);
    }
    
    public Tower setX(int x){
    	xPos = x;
    	return this;
    }
    
    public Tower setY(int y){
    	yPos = y;
    	return this;
    }
    
    /**
     * paints the Monster on the canvas. Also contains movement logic
     * @param g graphics context
     * @param xPos coordinate for reference pixel
     * @param yPos coordinate for reference pixel
     */
    public void paint(Graphics g){
        // for a first, the monster walks only upside
    	sprite.setRefPixelPosition(xPos*30, yPos*30);
        sprite.paint(g);
    }
    
    public String toString(){
    	return "T";
    }
}
